﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Mysoft.Rpa.ControlWeb.ApiClient;
using Mysoft.Rpa.ControlWeb.Models.Api;
using Newtonsoft.Json;

namespace Mysoft.Rpa.ControlWeb.Controllers
{
    /// <summary>
    /// 机器人相关
    /// </summary>
    public class RobotController : BaseController
    {
        /// <summary>
        /// 获取机器人列表
        /// </summary>
        /// <param name="keywords"></param>
        /// <param name="page"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        [HttpGet]
        [HttpPost]

        public IActionResult List(string keywords, int page = 1, int size = 1)
        {
            if (HttpContext.Request.Method.ToUpper() == "GET")
                return View();
            
            var data = HttpHelper.GetApi<HttpRequestResult<List<RobotInfo>>>("Robot");
            return Json(data);
        }
        
        /// <summary>
        /// 获取机器人的包列表
        /// </summary>
        /// <param name="robotGuid"></param>
        /// <returns></returns>
        [HttpGet]
        [HttpPost]

        public IActionResult Packages(Guid robotGuid)
        {
            if (HttpContext.Request.Method.ToUpper() == "GET")
                return View();

            var data = HttpHelper.GetApi<HttpRequestResult<List<RobotPackageInfo>>>($"PackageManagement/{robotGuid.ToString("D")}/querypackage");
            return Json(data);
        }

        /// <summary>
        /// 更新机器人的包安装状态
        /// </summary>
        /// <param name="paramDto"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UpdatePackageStatus([FromBody] UpdatePackageStatusDto paramDto)
        {
            var data = HttpHelper.PostApi<HttpRequestResult<bool>>("packagemanagement/updatepackagestatus", paramDto);
            return Json(data);
        }
    }
}